import logging

import allure
import jsonpath

from utils.send_request import send_jdbc_request


def json_extractor(case,all,res):
    if case["jsonExData"]:
        with allure.step("4.JSON提取"):
            # 首先要把 jsonExData 的 key, value 拆开
            for key, value in eval(case["jsonExData"]).items():
                value = jsonpath.jsonpath(res.json(), value)[0]
                all[key] = value
            logging.info(f"4、JSON提取，根据{case['jsonExData']}提取，此时全局变量为{all}")
def jdbc_extractor(case,all):
    if case["sqlExData"]:
        with allure.step("4.JDBC提取"):
            for key, value in eval(case["sqlExData"]).items():
                all[key] = send_jdbc_request(value)
            logging.info(f"4、JDBC提取，根据{case["sqlExData"]}提取，此时全局变量为{all}")